package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.DailyComment;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDailyCommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("dailyComment")
public class DailyCommentController {
    @Autowired
    private IDailyCommentService dailyCommentService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        //根据创建时间倒序
        qo.setOrderBy("dc.createTime desc");
        PageInfo pageInfo = dailyCommentService.queryAdmin(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "daily/commentList";
    }

    @RequestMapping("getContentById")
    @ResponseBody
    public DailyComment getContentById(Long id) {
        return dailyCommentService.getContentById(id);
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) {
        dailyCommentService.delete(id);
        return new JSONResult();
    }
}
